package com.alma.talk;

import org.omg.CORBA.ORB;

import com.alma.MTalk.Talk;
import com.alma.MTalk.TalkHelper;

public class Talker {

	private short conversationId;
	private String talkIor;
	private Talk talk;
	private String infos;
	private String subject;
	private ORB orb;
	

	/**
	 * 
	 * @param orb L'ORB
	 * @param subject Le sujet de conversation
	 * @param conversationId Numéro the conversation du demandant
	 * @param talkIor IOR du talk du demandant
	 * @param infos Son pseudo
	 */
	public Talker(ORB orb,String subject,short conversationId, String talkIor, String infos) {
		super();
		this.conversationId = conversationId;
		this.talkIor = talkIor;
		this.infos = infos;
		this.subject = subject;
		this.orb = orb;
		resolveTalk(orb);
	}


	/**
	 * @return the conversationId
	 */
	public short getConversationId() {
		return conversationId;
	}


	/**
	 * @param conversationId the conversationId to set
	 */
	public void setConversationId(short conversationId) {
		this.conversationId = conversationId;
	}


	/**
	 * @return the talkIor
	 */
	public String getTalkIor() {
		return talkIor;
	}


	/**
	 * @param talkIor the talkIor to set
	 */
	public void setTalkIor(String talkIor) {
		this.talkIor = talkIor;
		resolveTalk(orb);
	}


	/**
	 * @return the talk
	 */
	public Talk getTalk() {
		return talk;
	}

	/**
	 * @return the infos
	 */
	public String getInfos() {
		return infos;
	}


	/**
	 * @param infos the infos to set
	 */
	public void setInfos(String infos) {
		this.infos = infos;
	}

 
	/**
	 * @return the subject
	 */
	public String getSubject() {
		return subject;
	}


	/**
	 * @param subject the subject to set
	 */
	public void setSubject(String subject) {
		this.subject = subject;
	}

	/**
	 *  Recupérer le talk distant
	 * @param orb
	 */
	private void resolveTalk(ORB orb){
		talk = TalkHelper.narrow(orb.string_to_object(talkIor));
	}
	
	/**
	 *  Envoyer un message
	 * @param message
	 */
	public void send(String message){
		if(talk!=null) talk.talk(conversationId, message);
	}
	
	/**
	 *  Arrete la conversation
	 */
	public void stop(){		
		if(talk!=null) talk.stop(conversationId);		
	}
	
}
